﻿import {
    useMutation,
    useQueryClient
} from "@tanstack/react-query";
import {
    createEditCabin
} from "../../services/apiCabins.js";
import toast from "react-hot-toast";
import {
    updateCurrentUser
} from "../../services/apiAuth.js";

export function useUpdateUser(){
    const queryClient = useQueryClient();

    const {mutate:updateUser,isLoading:isUpdating} = useMutation({
        mutationFn:updateCurrentUser,
        onSuccess:({ user })=>{
            toast.success('User account successfully updated');
            queryClient.setQueriesData("user",user);
        },
        onError:(err)=>toast.error(err.message),
    });

    return { updateUser,isUpdating };
}